﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LevelDB
{
    public struct Vector3Int : IEquatable<Vector3Int>
    {
        public int x, y, z;
        public Vector3Int(int x, int y, int z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        public static Vector3Int FromBytes(byte[] bytes, int startIndex)
        {
            var x = BitConverter.ToInt32(bytes, startIndex);
            var y = BitConverter.ToInt32(bytes, startIndex + sizeof(int));
            var z = BitConverter.ToInt32(bytes, startIndex + sizeof(int) * 2);
            return new Vector3Int(x, y, z);
        }

        public bool Equals(Vector3Int other)
        {
            return x == other.x && y == other.y && z == other.z;
        }

        public void GetBytes(byte[] bytes)
        {
            Buffer.BlockCopy(BitConverter.GetBytes(x), 0, bytes, 0, sizeof(int));
            Buffer.BlockCopy(BitConverter.GetBytes(y), 0, bytes, sizeof(int), sizeof(int));
            Buffer.BlockCopy(BitConverter.GetBytes(z), 0, bytes, sizeof(int) * 2, sizeof(int));
        }

        public override string ToString()
        {
            return $"({x},{y},{z})";
        }
    }
}
